package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.enums.model.OrderStatus;
import com.atguigu.gmall.order.client.OrderFeignClient;
import com.atguigu.gmall.order.model.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * title:
 * author: Gyh
 * date:2023-05-09 20:43
 * Description:
 */
@Controller
public class PaymentController {

    @Autowired
    private OrderFeignClient orderFeignClient;

    /**
     * 渲染选择支付页面
     * @param orderId
     * @return
     */
    @GetMapping("/pay.html")
    public String payChooseHtml(@RequestParam("orderId") Long orderId, Model model){
        //远程调用获取订单的信息
        OrderInfo orderInfo = orderFeignClient.getOrderInfoById(orderId);
        //判断订单的状态给静态页面赋值
        if (orderInfo != null && OrderStatus.UNPAID.name().equals(orderInfo.getOrderStatus())){
            model.addAttribute("orderInfo",orderInfo);
            return "/payment/pay";
        }
        throw new RuntimeException("订单状态异常");
    }

    /**
     * 用户支付成功后展示的页面
     * @return
     */
    @GetMapping("/pay/success.html")
    public String paySuccessHtml(){
        return "/payment/success";
    }
}
